package com.lagou.job;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.lagou.constants.RedisKeyConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisCluster;


@Component
public class RefreshCommendListJob {

    private static final Logger logger = LoggerFactory.getLogger(RefreshCommendListJob.class);

    @Autowired
    private JedisCluster jedisCluster;

    @Scheduled(cron = "0 */1 * * * ?")
    public void refresh() {
        // 通过大数据统计对应的24小时的推荐列表，设置到缓存中
        logger.info("统计并更新redis中的推荐列表");
        jedisCluster.set(RedisKeyConstants.getRecommendListKey(), JSON.toJSONString(Lists.newArrayList()));
    }
}
